package com.liao.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.liao.dao.BookinfoDao;
import com.liao.util.Result;

@RestController
public class BookinfoController {
@Autowired
  BookinfoDao bookinfoDao;

   @RequestMapping("/getBook")
   @ResponseBody
   public Object getBook(@RequestParam Map<String,Object> map) {
	   Integer page =Integer.parseInt(map.get("page").toString());
	   Integer limit =Integer.parseInt(map.get("limit").toString());
	   
	   map.put("limit", limit);
	   map.put("page", (page-1)*limit);
	   List<Map<String,Object>> user =bookinfoDao.getBookinfoList(map);
	   int count=bookinfoDao.getBookinfoCount();
Result res=new Result("0","true",count ,user );
	   return res;
	   
   }
   
   @RequestMapping("/addBook")
   @ResponseBody
   public Object addBookinfo(@RequestParam Map<String,Object> map) {
	   System.out.println(map.get("bname"));
	   int i=bookinfoDao.AddBookinfo(map);
	   Result res=new Result("0","true",i,true);
	   return res;
	   
   }
   
   @RequestMapping("/updateBookinfo")
   @ResponseBody
   public Object updateBookinfo(@RequestParam Map<String,Object>map) {
	   int i= bookinfoDao.UpdateBookinfo(map);
	   Result res=new Result("0","true",i,true);
	   return res;
   }
   
   @RequestMapping("/deleteBookinfo")
   @ResponseBody
   public Object deleteBookinfo(@RequestParam("bid") Integer bid) {
	   int i=bookinfoDao.DelectBookinfo(bid);
	   Result res=new Result("0","true",i,true);
	   return res;
   }
}
